package com.ruoyi.yljf.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.yljf.mapper.NewsMapper;
import com.ruoyi.yljf.domain.News;
import com.ruoyi.yljf.service.INewsService;

import javax.annotation.Resource;

/**
 * 系统消息Service业务层处理
 * 
 * @author TTTc
 * @date 2025-02-27
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements INewsService {
    @Resource
    private NewsMapper newsMapper;
    
    /**
     * 查询系统消息列表
     * 
     * @param news 系统消息
     * @return 系统消息
     */
    @Override
    public List<News> selectNewsList(News news) {
    	LambdaQueryWrapper<News> queryWrapper = Wrappers.lambdaQuery();
        if (StringUtils.isNotEmpty(news.getSysMes())) {
			queryWrapper.eq(News::getSysMes, news.getSysMes());
		}
        if (StringUtils.isNotNull(news.getUserId())) {
			queryWrapper.eq(News::getUserId, news.getUserId());
		}
        if (StringUtils.isNotNull(news.getIsRead())) {
			queryWrapper.eq(News::getIsRead, news.getIsRead());
		}
        queryWrapper.orderByDesc(News::getIsRead);
        return newsMapper.selectList(queryWrapper);
    }

    @Override
    public int allRead(Long uerId) {
        return newsMapper.update(new News(),new UpdateWrapper<News>().set("is_read",1).eq("user_id",uerId));

    }
}
